#ifndef ResultManager_H
#define ResultManager_H

#include <Ice/Ice.h>
#include <Magick++.h>
#include <FileManager.h>
#include <Yafridng.h>

using namespace Yafridng;
using namespace Magick;

class Retrieve : public IceUtil::Shared
{
 public:
 Retrieve(const AMD_YafridngRenderManager_updateZonePtr& cb,
	  const int width,
	  const int height,
	  const TZone& zone,
	  const string& image,
	  const int sceneType,
	  const string& result,
	  const FileManager& file) : 
  _cb(cb),
    _width(width),
    _height(height),
    _zone(zone),
    _image(image),
    _sceneType(sceneType),
    _file(file),
    _result(result)
  {
  }

  void perform();
  void cancel();

 private:
  TZone getFinalDimensions(TZone z, int ib, int width, int height);

  AMD_YafridngRenderManager_updateZonePtr _cb;
  TZone _zone;
  int _width;
  int _height;
  int _sceneType;
  FileManager _file;
  string _result;
  string _image;
};
typedef IceUtil::Handle<Retrieve> RetrievePtr;

class ResultManager : public IceUtil::Shared,
  public IceUtil::Monitor<IceUtil::Mutex>
{
 public:
 ResultManager(string image, int sceneType) :
  _destroy(false),
    _image(image),
    _sceneType(sceneType),
    _lastZone(false)
    {
    }

  void add(const AMD_YafridngRenderManager_updateZonePtr& cb,
	   const int width,
	   const int weight,
	   const TZone& zone,
	   const string& result,
	   const FileManager& file);
  bool perform();
  void lastZone();
  void destroy();
  bool getDestroy();

 private:
  bool _destroy;
  vector<RetrievePtr> _retrieves;
  string _image;
  int _sceneType;
  bool _lastZone;
};
typedef IceUtil::Handle<ResultManager> ResultManagerPtr;

#endif
